<template>
  <div id="d1">
  <div id="div1" style="display:inline-block;">
    <span class="demonstration"></span>
    <el-carousel :height="screenheight">
      <el-carousel-item v-for="item in tupian" :key="item.id">
        <img :src="item.idView"  class="image">
      </el-carousel-item>
    </el-carousel>
  </div>
  <div id="login1" style=" height:100%; display:inline-block;">
    <el-form :rules="rules" ref="loginForm" :model="loginForm" class="loginContainer">
      <h3 class="loginTitle">登录</h3>
      <el-form-item prop="userName">
        <el-input type="text" auto-complete="false" v-model="loginForm.userName" placeholder="请输入用户名"></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input type="password" auto-complete="false" v-model="loginForm.password" placeholder="请输入密码"></el-input>
      </el-form-item>
      <div style="position: relative;padding-right: 100px;">
        <el-form-item prop="code">
          <el-input  type="text" auto-complete="false" v-model="loginForm.code" placeholder="点击图片更换验证码" style="width: 245px;margin-right: 5px;"></el-input>
          <img style="display: inline-block;position: absolute" :src="captchaUrl" @click="updateCaptcha">
        </el-form-item>
      </div>
      <el-checkbox v-model="checked" class="loginRemember" style="float:left">记住我</el-checkbox>
      <el-button type="primary" style="width: 100%" @click="submitLogin">登录</el-button>
    </el-form>
  </div>
</div>
</template>

<script>
export default {
  name: 'LoginView',
  data () {
    return {
      screenheight: document.documentElement.clientHeight + 'px',
      tupian: [{ id: 0, idView: require('../assets/lunbo1.png') },
        { id: 1, idView: require('../assets/lunbo2.png') },
        { id: 2, idView: require('../assets/lunbo3.png') }],
      captchaUrl: 'http://localhost:8090/captcha?time=' + new Date(),
      loginForm: {
        userName: 'admin',
        password: '1234',
        code: ''
      },
      checked: true,
      rules: {
        userName: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
        code: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
      }
    }
  },
  methods: {
    updateCaptcha () {
      this.captchaUrl = 'http://localhost:8090/captcha?time=' + new Date()
    },
    submitLogin () {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.request.post('/d-user/login', this.loginForm).then(res => {
            console.log(res.data)
            if (res.code === '200') {
              // sessionStorage.setItem('user', JSON.stringify(res.data.user))
              // sessionStorage.setItem('token', JSON.stringify(res.data.token))
              this.$store.commit('SET_Token', JSON.stringify(res.data.token))
              this.$store.commit('SET_USERINFO', res.data.user)
              this.$store.commit('setMenu', res.data.menuList)
              this.$router.replace('/home')
              this.$message.success(res.msg)
            }
          })
        } else {
          this.$message.error('请输入所有字段！')
          return false
        }
      })
    }
  },
  mounted () {
    window.onresize = () => {
      return () => {
        this.screenheight = document.documentElement.clientHeight + 'px'
      }
    }
  }
}
</script>

<style>
  *{
    margin: 0px;
    padding:0px;
  }
 .el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    line-height: 150px;
    margin: 0;
  }

  .el-carousel__item:nth-child(2n) {
     /* background-color: #99a9bf; */
     background-image: url(../assets/loginbeij.png);
     background-repeat:no-repeat;
     background-position:50%;
     background-size:cover;
  }

  .el-carousel__item:nth-child(2n+1) {
    background-image: url(../assets/loginbeij.png);
     background-repeat:no-repeat;
     background-position:50%;
     background-size: cover;
  }
  #d1{
    position: relative;
    height:auto
  }
  #div1{
    width:50%;
    height:100%;
     position: fixed;
    position: absolute;
    right: 735px;
    position:fixed;
  }
  #login1{
    height:700px;
    width: 50%;
    background-repeat:no-repeat;
     background-position:50%;
     background-size:cover;
     position: absolute;
  }
  .image{
/*设置图片宽度和浏览器宽度一致*/
  width:600px;
  height: 600px;
  object-fit: contain;
  height:inherit;
  /* float:left */
}
.loginContainer{
    border-radius: 15px;
    background-clip: padding-box;
    margin: 180px auto;
    width: 350px;
    padding: 15px 35px 15px 35px;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
    position: absolute;
    right: 100px;
    top:-100px;
    position:fixed;
  }
  .loginTitle{
    margin: 0px auto 40px auto;
    text-align: center;
  }
  .loginRemember{
    text-align: left;
    margin: 0px 0px 15px 0px;
  }
</style>
